#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL)". You may
# only use this file in accordance with the terms of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2013 EveryCity Ltd. All rights reserved.
# Copyright 2014 Alexander Pyhalov. All rights reserved.
#

include ../../../make-rules/shared-macros.mk

COMPONENT_NAME=		openoffice
COMPONENT_VERSION=      4.1.1
COMPONENT_REVISION=	1
COMPONENT_PROJECT_URL=  http://openoffice.apache.org/ 
COMPONENT_SUMMARY=	Apache OpenOffice Suite
COMPONENT_SRC=		aoo-$(COMPONENT_VERSION)
COMPONENT_ARCHIVE=	apache-openoffice-$(COMPONENT_VERSION)-r1617669-src.tar.bz2
COMPONENT_ARCHIVE_HASH=	sha256:bb89a6d2324ddfe4c475e5484fde0dea316078f6b8ff4d8a4ebc801d17f3ff9f
COMPONENT_ARCHIVE_URL=	https://archive.apache.org/dist/openoffice/$(COMPONENT_VERSION)/source/$(COMPONENT_ARCHIVE)

COMPONENT_ARCHIVE_1=0168229624cfac409e766913506961a8-ucpp-1.3.2.tar.gz
COMPONENT_ARCHIVE_HASH_1=md5:0168229624cfac409e766913506961a8
COMPONENT_ARCHIVE_URL_1=http://ucpp.googlecode.com/files/ucpp-1.3.2.tar.gz

COMPONENT_ARCHIVE_2=067201ea8b126597670b5eff72e1f66c-mythes-1.2.0.tar.gz
COMPONENT_ARCHIVE_HASH_2=md5:067201ea8b126597670b5eff72e1f66c
COMPONENT_ARCHIVE_URL_2=http://sourceforge.net/projects/hunspell/files/MyThes/1.2.0/mythes-1.2.0.tar.gz/download

COMPONENT_ARCHIVE_3=0dd138efff4412c707e239290fb82d4f-mdds_0.3.1.tar.bz2
COMPONENT_ARCHIVE_HASH_3=md5:0dd138efff4412c707e239290fb82d4f
COMPONENT_ARCHIVE_URL_3=http://multidimalgorithm.googlecode.com/files/mdds_0.3.1.tar.bz2

COMPONENT_ARCHIVE_4=128cfc86ed5953e57fe0f5ae98b62c2e-libtextcat-2.2.tar.gz
COMPONENT_ARCHIVE_HASH_4=md5:128cfc86ed5953e57fe0f5ae98b62c2e
COMPONENT_ARCHIVE_URL_4=http://software.wise-guys.nl/download/libtextcat-2.2.tar.gz

COMPONENT_ARCHIVE_5=17410483b5b5f267aa18b7e00b65e6e0-hsqldb_1_8_0.zip
COMPONENT_ARCHIVE_HASH_5=md5:17410483b5b5f267aa18b7e00b65e6e0
COMPONENT_ARCHIVE_URL_5=http://sourceforge.net/projects/hsqldb/files/hsqldb/hsqldb_1_8_0/hsqldb_1_8_0_10.zip/download

COMPONENT_ARCHIVE_6=1756c4fa6c616ae15973c104cd8cb256-Adobe-Core35_AFMs-314.tar.gz
COMPONENT_ARCHIVE_HASH_6=md5:1756c4fa6c616ae15973c104cd8cb256
COMPONENT_ARCHIVE_URL_6=http://ooo-extras.apache-extras.org.codespot.com/files/1756c4fa6c616ae15973c104cd8cb256-Adobe-Core35_AFMs-314.tar.gz

COMPONENT_ARCHIVE_7=17960f35b2239654ba608cf1f3e256b3-lucene-2.9.4-src.tar.gz
COMPONENT_ARCHIVE_HASH_7=md5:17960f35b2239654ba608cf1f3e256b3
COMPONENT_ARCHIVE_URL_7=http://archive.apache.org/dist/lucene/java/2.9.4/lucene-2.9.4-src.tar.gz

COMPONENT_ARCHIVE_8=1f24ab1d39f4a51faf22244c94a6203f-xmlsec1-1.2.14.tar.gz
COMPONENT_ARCHIVE_HASH_8=md5:1f24ab1d39f4a51faf22244c94a6203f
COMPONENT_ARCHIVE_URL_8=http://ooo-extras.apache-extras.org.codespot.com/files/1f24ab1d39f4a51faf22244c94a6203f-xmlsec1-1.2.14.tar.gz

COMPONENT_ARCHIVE_9=24be19595acad0a2cae931af77a0148a-LICENSE_source-9.0.0.7-bj.html
COMPONENT_ARCHIVE_HASH_9=md5:24be19595acad0a2cae931af77a0148a
COMPONENT_ARCHIVE_URL_9=http://ooo-extras.apache-extras.org.codespot.com/files/24be19595acad0a2cae931af77a0148a-LICENSE_source-9.0.0.7-bj.html

COMPONENT_ARCHIVE_10=284e768eeda0e2898b0d5bf7e26a016e-raptor-1.4.18.tar.gz
COMPONENT_ARCHIVE_HASH_10=md5:284e768eeda0e2898b0d5bf7e26a016e
COMPONENT_ARCHIVE_URL_10=http://download.librdf.org/source/raptor-1.4.18.tar.gz

COMPONENT_ARCHIVE_11=2b5f1ca58d6ef30f18f1415b65bed81c-CoinMP-1.6.0.tgz
COMPONENT_ARCHIVE_HASH_11=md5:2b5f1ca58d6ef30f18f1415b65bed81c
COMPONENT_ARCHIVE_URL_11=http://ooo-extras.apache-extras.org.codespot.com/files/2b5f1ca58d6ef30f18f1415b65bed81c-CoinMP-1.6.0.tgz

COMPONENT_ARCHIVE_12=2f6ecca935948f7db92d925d88d0d078-icu4c-4_0_1-src.tgz
COMPONENT_ARCHIVE_HASH_12=md5:2f6ecca935948f7db92d925d88d0d078
COMPONENT_ARCHIVE_URL_12=http://download.icu-project.org/files/icu4c/4.0.1/icu4c-4_0_1-src.tgz

COMPONENT_ARCHIVE_13=3121aaf3e13e5d88dfff13fb4a5f1ab8-hunspell-1.3.2.tar.gz
COMPONENT_ARCHIVE_HASH_13=md5:3121aaf3e13e5d88dfff13fb4a5f1ab8
COMPONENT_ARCHIVE_URL_13=http://sourceforge.net/projects/hunspell/files/Hunspell/1.3.2/hunspell-1.3.2.tar.gz/download

COMPONENT_ARCHIVE_14=35efabc239af896dfb79be7ebdd6e6b9-gentiumbasic-fonts-1.10.zip
COMPONENT_ARCHIVE_HASH_14=md5:35efabc239af896dfb79be7ebdd6e6b9
COMPONENT_ARCHIVE_URL_14=http://ooo-extras.apache-extras.org.codespot.com/files/35efabc239af896dfb79be7ebdd6e6b9-gentiumbasic-fonts-1.10.zip

COMPONENT_ARCHIVE_15=3ade8cfe7e59ca8e65052644fed9fca4-epm-3.7.tar.gz
COMPONENT_ARCHIVE_HASH_15=md5:3ade8cfe7e59ca8e65052644fed9fca4
COMPONENT_ARCHIVE_URL_15=http://www.msweet.org/files/project2/epm-3.7-source.tar.gz

COMPONENT_ARCHIVE_16=48470d662650c3c074e1c3fabbc67bbd-README_source-9.0.0.7-bj.txt
COMPONENT_ARCHIVE_HASH_16=md5:48470d662650c3c074e1c3fabbc67bbd
COMPONENT_ARCHIVE_URL_16=http://ooo-extras.apache-extras.org.codespot.com/files/48470d662650c3c074e1c3fabbc67bbd-README_source-9.0.0.7-bj.txt

COMPONENT_ARCHIVE_17=48a9f787f43a09c0a9b7b00cd1fddbbf-hyphen-2.7.1.tar.gz
COMPONENT_ARCHIVE_HASH_17=md5:48a9f787f43a09c0a9b7b00cd1fddbbf
COMPONENT_ARCHIVE_URL_17=http://sourceforge.net/projects/hunspell/files/Hyphen/2.7/hyphen-2.7.1.tar.gz

COMPONENT_ARCHIVE_18=52654eb3b2e60c35731ea8fc87f1bd29-jpeg-8d.tar.gz
COMPONENT_ARCHIVE_HASH_18=md5:52654eb3b2e60c35731ea8fc87f1bd29
COMPONENT_ARCHIVE_URL_18=http://www.ijg.org/files/jpegsrc.v8d.tar.gz

COMPONENT_ARCHIVE_19=61f59e4110781cbe66b46449eadac231-croscorefonts-1.21.0.tar.gz
COMPONENT_ARCHIVE_HASH_19=md5:61f59e4110781cbe66b46449eadac231
COMPONENT_ARCHIVE_URL_19=http://ooo-extras.apache-extras.org.codespot.com/files/61f59e4110781cbe66b46449eadac231-croscorefonts-1.21.0.tar.gz

COMPONENT_ARCHIVE_20=63574e3ada44f473892a61a2da433a59-apache-tomcat-5.5.36-src.tar.gz
COMPONENT_ARCHIVE_HASH_20=md5:63574e3ada44f473892a61a2da433a59
COMPONENT_ARCHIVE_URL_20=http://archive.apache.org/dist/tomcat/tomcat-5/v5.5.36/src/apache-tomcat-5.5.36-src.tar.gz

COMPONENT_ARCHIVE_21=80143f96b3f6ce45d2e4947da21a5e9-stax-src-1.2.0.zip
COMPONENT_ARCHIVE_HASH_21=md5:980143f96b3f6ce45d2e4947da21a5e9
COMPONENT_ARCHIVE_URL_21=http://distfiles.gentoo.org/distfiles/stax-src-1.2.0.zip

COMPONENT_ARCHIVE_22=99d94103662a8d0b571e247a77432ac5-rhino1_7R3.zip
COMPONENT_ARCHIVE_HASH_22=md5:99d94103662a8d0b571e247a77432ac5
COMPONENT_ARCHIVE_URL_22=http://ftp.mozilla.org/pub/mozilla.org/js/rhino1_7R3.zip

COMPONENT_ARCHIVE_23=ada24d37d8d638b3d8a9985e80bc2978-source-9.0.0.7-bj.zip
COMPONENT_ARCHIVE_HASH_23=md5:ada24d37d8d638b3d8a9985e80bc2978
COMPONENT_ARCHIVE_URL_23=http://ooo-extras.apache-extras.org.codespot.com/files/ada24d37d8d638b3d8a9985e80bc2978-source-9.0.0.7-bj.zip

COMPONENT_ARCHIVE_24=ca66e26082cab8bb817185a116db809b-redland-1.0.8.tar.gz
COMPONENT_ARCHIVE_HASH_24=md5:ca66e26082cab8bb817185a116db809b
COMPONENT_ARCHIVE_URL_24=http://download.librdf.org/source/redland-1.0.8.tar.gz

COMPONENT_ARCHIVE_25=d62650a6f908e85643e557a236ea989c-vigra1.6.0.tar.gz
COMPONENT_ARCHIVE_HASH_25=md5:d62650a6f908e85643e557a236ea989c
COMPONENT_ARCHIVE_URL_25=http://pkgs.fedoraproject.org/repo/pkgs/vigra/vigra1.6.0.tar.gz/d62650a6f908e85643e557a236ea989c/vigra1.6.0.tar.gz

COMPONENT_ARCHIVE_26=dd7dab7a5fea97d2a6a43f511449b7cd-expat-2.1.0.tar.gz
COMPONENT_ARCHIVE_HASH_26=md5:dd7dab7a5fea97d2a6a43f511449b7cd
COMPONENT_ARCHIVE_URL_26=http://sourceforge.net/projects/expat/files/expat/2.1.0/expat-2.1.0.tar.gz/download

COMPONENT_ARCHIVE_27=ea570af93c284aa9e5621cd563f54f4d-bsh-2.0b1-src.tar.gz
COMPONENT_ARCHIVE_HASH_27=md5:ea570af93c284aa9e5621cd563f54f4d
COMPONENT_ARCHIVE_URL_27=http://ooo-extras.apache-extras.org.codespot.com/files/ea570af93c284aa9e5621cd563f54f4d-bsh-2.0b1-src.tar.gz

COMPONENT_ARCHIVE_28=f65fbbd72926c8e7cf0dbd4ada03b0d226f461fd-serf-1.2.1.tar.bz2
COMPONENT_ARCHIVE_HASH_28=sha256:6988d394b62c3494635b6f0760bc3079f9a0cd380baf0f6b075af1eb9fa5e700
COMPONENT_ARCHIVE_URL_28=http://serf.googlecode.com/files/serf-1.2.1.tar.bz2

COMPONENT_ARCHIVE_29=f872f4ac066433d8ff92f5e316b36ff9-dejavu-fonts-ttf-2.33.zip
COMPONENT_ARCHIVE_HASH_29=md5:f872f4ac066433d8ff92f5e316b36ff9
COMPONENT_ARCHIVE_URL_29=http://sourceforge.net/projects/dejavu/files/dejavu/2.33/dejavu-fonts-ttf-2.33.zip/download

COMPONENT_ARCHIVE_30=fca8706f2c4619e2fa3f8f42f8fc1e9d-rasqal-0.9.16.tar.gz
COMPONENT_ARCHIVE_HASH_30=md5:fca8706f2c4619e2fa3f8f42f8fc1e9d
COMPONENT_ARCHIVE_URL_30=http://download.librdf.org/source/rasqal-0.9.16.tar.gz

COMPONENT_ARCHIVE_31=fdb27bfe2dbe2e7b57ae194d9bf36bab-SampleICC-1.3.2.tar.gz
COMPONENT_ARCHIVE_HASH_31=md5:fdb27bfe2dbe2e7b57ae194d9bf36bab
COMPONENT_ARCHIVE_URL_31=http://ooo-extras.apache-extras.org.codespot.com/files/fdb27bfe2dbe2e7b57ae194d9bf36bab-SampleICC-1.3.2.tar.gz

NUM_EXTRA_ARCHIVES=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

include $(WS_TOP)/make-rules/prep.mk
include $(WS_TOP)/make-rules/configure.mk
include $(WS_TOP)/make-rules/ips.mk

PATH=$(GCC_ROOT)/bin:/opt/openoffice/bin:/usr/gnu/bin:/usr/bin

PKG_CONFIG_PATH=/usr/apr/lib/pkgconfig:/usr/apr-util/lib/pkgconfig:/usr/lib/pkgconfig

COMPONENT_BUILD_ENV=	CONFIG_SHELL="$(CONFIG_SHELL)"
COMPONENT_BUILD_ENV+=	SHELL="$(CONFIG_SHELL)"
#COMPONENT_BUILD_ENV+=	PATH="$(PATH)"
COMPONENT_BUILD_ENV+=	CC="$(CC)"
COMPONENT_BUILD_ENV+=	CXX="$(CXX)"
COMPONENT_BUILD_ENV+=	F77="$(F77)"
COMPONENT_BUILD_ENV+=	FC="$(FC)"

CONFIGURE_ENV = $(COMPONENT_BUILD_ENV)
CONFIGURE_ENV += PYTHON=/usr/bin/python2.7

COMPONENT_PREP_ACTION= ( cd $(@D)/main && autoconf && \
	mkdir -p $(@D)/ext_sources/ && \
	for i in $(ARCHIVES) ; do rm -f $(@D)/ext_sources/$$i && \
	ln -s $(USERLAND_ARCHIVES)/$$i $(@D)/ext_sources/$$i ; done )

# Configure OpenOffice
$(BUILD_DIR)/%/.configured:     $(SOURCE_DIR)/.prep
	($(RM) -rf $(@D) ; $(MKDIR) $(@D) && \
	 cp -a $(SOURCE_DIR)/* $(@D) && \
	 $(MKDIR) $(COMPONENT_DIR)/build/bin && \
	 rm -f $(COMPONENT_DIR)/build/bin/strip && \
	 ln -s /usr/bin/strip $(COMPONENT_DIR)/build/bin/strip && \
	 cp $(COMPONENT_DIR)/files/unowinreg.dll $(@D)/main/external/unowinreg/)
	(cd $(@D)/main && $(ENV) $(CONFIGURE_ENV) $(CONFIG_SHELL) \
		./configure $(CONFIGURE_OPTIONS))
	$(TOUCH) $@

# Build OpenOffice
$(BUILD_DIR)/%/.built:  $(BUILD_DIR)/%/.configured
	( $(ENV) -i $(COMPONENT_BUILD_ENV) $(CONFIG_SHELL) -c  "cd $(@D)/main/instsetoo_native  && source ../SolarisX86GccEnv.Set.sh && ulimit -s unlimited && build.pl --all -P4 -- -P4")
	$(TOUCH) $@

# Install OpenOffice
$(BUILD_DIR)/%/.installed:  $(BUILD_DIR)/%/.built
	$(RM) -r $(PROTO_DIR)/opt/openoffice
	$(MKDIR) $(PROTO_DIR)/opt/openoffice
	$(CP) -a $(BUILD_DIR_32)/main/instsetoo_native/unxsogi.pro/Apache_OpenOffice/installed/install/en/* $(PROTO_DIR)/opt/openoffice
	$(MKDIR) $(PROTO_DIR)/usr/share/icons
	$(CP) -a $(BUILD_DIR_32)/main/sysui/desktop/icons/hicolor $(PROTO_DIR)/usr/share/icons/
	$(MKDIR) $(PROTO_DIR)/usr/share/mime-info
	cat  $(BUILD_DIR_32)/main/sysui/desktop/mimetypes/*.keys > $(PROTO_DIR)/usr/share/mime-info/openoffice4.keys
	$(CP)  $(BUILD_DIR_32)/main/sysui/desktop/mimetypes/openoffice.mime $(PROTO_DIR)/usr/share/mime-info/openoffice4.mime
	$(MKDIR) $(PROTO_DIR)/usr/share/application-registry
	$(CP)  $(BUILD_DIR_32)/main/sysui/desktop/mimetypes/openoffice.applications $(PROTO_DIR)/usr/share/application-registry/openoffice4.applications
	$(MKDIR) $(PROTO_DIR)/usr/share/mime/packages
	$(CP)  $(BUILD_DIR_32)/main/sysui/unxsogi.pro/misc/openoffice/apacheopenoffice.xml $(PROTO_DIR)/usr/share/mime/packages/openoffice4.xml
	$(GSED) -i -e 's/^UserInstallation.*$$/UserInstallation=$$SYSUSERCONFIG\/\.openoffice\.org\/4/' $(PROTO_DIR)/opt/openoffice/openoffice4/program/bootstraprc
	chmod u+w $(PROTO_DIR)/opt/openoffice/openoffice4/program/*
	/usr/bin/elfedit -e 'dyn:value -s  RPATH "$$ORIGIN:/usr/lib"' $(PROTO_DIR)/opt/openoffice/openoffice4/program/PresenterScreen.uno.so
	/usr/bin/elfedit -e 'dyn:value -s  RPATH "$$ORIGIN:/usr/lib"' $(PROTO_DIR)/opt/openoffice/openoffice4/program/PresentationMinimizer.uno.so
	/usr/bin/elfedit -e 'dyn:value -s  RPATH "$$ORIGIN:/usr/lib"' $(PROTO_DIR)/opt/openoffice/openoffice4/program/librdf.so.0
	/usr/bin/elfedit -e 'dyn:value -s  RPATH "$$ORIGIN:/usr/jdk/instances/openjdk1.7.0/jre/lib/i386:/usr/lib"' $(PROTO_DIR)/opt/openoffice/openoffice4/program/libofficebean.so
	$(TOUCH) $@

CONFIGURE_PREFIX = /opt/openoffice

CONFIGURE_OPTIONS+= --without-junit
CONFIGURE_OPTIONS+= --enable-category-b
CONFIGURE_OPTIONS+= --with-lang=en
CONFIGURE_OPTIONS+= --with-dict=ALL
CONFIGURE_OPTIONS+= --with-vendor="OpenIndiana Project"
CONFIGURE_OPTIONS+= --with-package-format=installed
CONFIGURE_OPTIONS+= --with-jdk-home=/usr/jdk/openjdk1.7.0
CONFIGURE_OPTIONS+= --without-stlport
CONFIGURE_OPTIONS+= --with-dmake-path=/opt/openoffice/bin/dmake
CONFIGURE_OPTIONS+= --with-epm-url=http://www.msweet.org/files/project2/epm-3.7-source.tar.gz
CONFIGURE_OPTIONS+= --with-system-apr
CONFIGURE_OPTIONS+= --with-system-apr-util
CONFIGURE_OPTIONS+= --with-system-boost
CONFIGURE_OPTIONS+= --with-system-cairo
CONFIGURE_OPTIONS+= --with-system-curl
CONFIGURE_OPTIONS+= --with-system-libxml
CONFIGURE_OPTIONS+= --with-system-libxslt
CONFIGURE_OPTIONS+= --with-system-nss
CONFIGURE_OPTIONS+= --with-system-jpeg
CONFIGURE_OPTIONS+= --with-system-openssl
CONFIGURE_OPTIONS+= --with-system-poppler
CONFIGURE_OPTIONS+= --with-system-python
CONFIGURE_OPTIONS+= --with-system-zlib

build:		$(BUILD_32)

install:	$(INSTALL_32)
